/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class code3 {
    // 相交链表
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode A = headA,B = headB;
        //都走三段长度（一样的）
        while( A != B) {
            if(A == null) {
                A = headB;
            } else {
                A = A.next;
            }

            if(B == null) {
                B = headA;
            } else {
                B = B.next;
            }
        }

        return A;
    }
}